package com.jianganming.chain;

import java.util.List;
import java.util.Map;

public class AuthHandler extends Handler<Member> {
    //实现权限校验的处理环节
    @Override
    public void doHandler(Member member) {
        DateSource dateSource = DateSource.getDateSourceInstance();
        Map<String, List<Role>> listMap = dateSource.getRole();
        List<Role> roleList = listMap.get(member.getLoginName());
        if(roleList==null){
            System.out.println("您没有"+member.getRoleName()+"权限");
            return;
        }
        boolean isfind = false;
        for (Role role : roleList) {
            if(role.getRoleName().equals(member.getRoleName())){
                isfind = true;
            }
        }
        if(!isfind){
            System.out.println("您不是"+member.getRoleName()+"角色，没有权限操作");
        }else {
            if(next != null){
                System.out.println("权限校验成功");
                next.doHandler(member);
            }
        }

    }
}
